﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Dack_Web2.DTO;
using System.Data.OleDb;

namespace Dack_Web2.DAO
{
    public class DealDAO
    {
        public void Insert(DealDTO tmp)
        {
          
            string str = "insert into Deal(MaSanPham, Giam, NgayBatDau, NgayKetThuc, SoLuong, XacNhan) values (@MaSanPham, @Giam, @NgayBatDau, @NgayKetThuc, @SoLuong, @XacNhan)";

            OleDbParameter[] para1 ={ new OleDbParameter("@MaSanPham", tmp.MaSanPham),
                                      new OleDbParameter("@Giam", tmp.Giam),
                                      new OleDbParameter("@NgayBatDau", tmp.NgayBatDau),
                                      new OleDbParameter("@NgayKetThuc", tmp.NgayKetThuc),
                                      new OleDbParameter("@SoLuong", tmp.SoLuong),
                                      new OleDbParameter("@XacNhan", tmp.XacNhan)};
            Sql_DataProvider.SQL_ExecuteNonQuery(str, para1);
        }

        public void Update(DealDTO tmp)
        {
            
            string str = "update Deal set MaSanPham=@MaSanPham, Giam=@Giam, NgayBatDau=@NgayBatDau, NgayKetThuc=@NgayKetThuc, SoLuong=@SoLuong, XacNhan=@XacNhan where MaDeal=@MaDeal";
           
            OleDbParameter[] para1 = {new OleDbParameter("@MaSanPham", tmp.MaSanPham),
                                    new OleDbParameter("@Giam", tmp.Giam),
                                    new OleDbParameter("@NgayBatDau", tmp.NgayBatDau),
                                    new OleDbParameter("@NgayKetThuc", tmp.NgayKetThuc),
                                    new OleDbParameter("@SoLuong", tmp.SoLuong),
                                    new OleDbParameter("@XacNhan", tmp.XacNhan),
                                    new OleDbParameter("@MaDeal", tmp.MaDeal)};
            Sql_DataProvider.SQL_ExecuteNonQuery(str, para1);
        }

        public void Delete(DealDTO tmp)
        {
            OleDbConnection cn = Sql_DataProvider.SQLConnect();
            string str = "delete from Deal where MaDeal=@MaDeal";
            OleDbCommand cmd = new OleDbCommand(str, cn);

            OleDbParameter para1 = new OleDbParameter("@MaDeal", tmp.MaDeal);

            cmd.Parameters.Add(para1);

            cmd.ExecuteNonQuery();

            cn.Close();
        }
    }
}